package com.example.employee.config;

import com.github.xiaoymin.knife4j.spring.extension.OpenApiExtensionResolver;
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.oas.annotations.EnableOpenApi;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

@Configuration
@EnableOpenApi
@RequiredArgsConstructor
public class SwaggerConfiguration {

    private final OpenApiExtensionResolver openApiExtensionResolver;

    @Bean
    @Order(value = 1)
    public Docket docDocket() {
        return new Docket(DocumentationType.OAS_30).
                pathMapping("/doc")
                .enable(true)
                .apiInfo(groupApiInfo())
                .select()
                .apis(RequestHandlerSelectors.withMethodAnnotation(Operation.class))
                .paths(PathSelectors.any())
                .build()
                .extensions(openApiExtensionResolver.buildExtensions("员工微服务"))
                ;
    }

    private ApiInfo groupApiInfo() {
        return new ApiInfoBuilder()
                .title("Knife4j接口文档")
                .description("Knife4j接口文档")
                .termsOfServiceUrl("https://doc.xiaominfo.com/")
                .version("1.0.0")
                .build();
    }

}
